﻿var Url = "AjaxData/CustomOperating.aspx";
var vname = "";
//自动义双击方法
function CustomDbClick() {
    window.parent.parent.$("#tabs").tabs('close', '查看客户信息');
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    vname = record.getData("CustomerName");
    var vid = record.getData(const_entityID);
    var pagetitle = "查看客户信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=3&flag=0&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
    //parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//自定义新增方法
var fnCustomAdd = function () {
    var SaveUrl = Url + "?r=" + Math.random() + "&action=check&entity=CrmCustomerCheck&json=&id=0";
    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    reloadData();
                }
                else {
                    alert(str);
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}
var reloadData = function () {
    window.parent.parent.$("#tabs").tabs('close', '新增客户信息');
    var pagetitle = "新增客户信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=3&flag=1&entity=' + const_EditEntity + '&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//自定义修改方法
var fnCustomEdit = function () {
    var vid = record.getData(const_entityID);
    window.parent.parent.$("#tabs").tabs('close', '修改客户信息');
    vname = record.getData("CustomerName");
    var pagetitle = "修改客户信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=3&flag=2&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//自定义删除方法
var fnCustomDeleteData = function () {
    YAHOO.example.container.dialog3.hide();
}
//添加联系人
var fnAddLinkMan = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    var pagetitle = "新增联系人信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/EditCrmManager.aspx?cid=' + vid + '&type=1&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//添加拜访记录
var fnAddLinkActivity = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    var pagetitle = "新增工作记录";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/EditCrmCallOn.aspx?cid=' + vid + '&type=1&&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//停用客户列表
var fnCustomerStopList = function () {
    window.parent.parent.$("#tabs").tabs('close', '停用客户列表');
    var pagetitle = "停用客户列表";
    parent.parent.addTabs(pagetitle, '../Extend/YUIList.aspx?entity=V_CrmCustomerInfoStop&order=Code&r=' + Math.random() + '&functionID=7307bf9b-aa43-41f4-b4d4-29df8cb9743a&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}


//客户分配
var fnCustomerFP = function () {
    var list = mDataTable.getRecordSet()._records;
    var elist = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
        }
    }
    _Ids = elist;
    if (_Ids.length > 0) {
        if (_Ids.length == 1) { //单个分配
            var recordID = myDataTable.getSelectedRows()[0];
            var record = myDataTable.getRecord(recordID);
            var vid = record.getData(const_entityID);
            var CustomerName = record.getData("CustomerName");
            var Decisionmaker = record.getData("Decisionmaker");
            var Code = record.getData("Code");
            if (vid != "") {
                //document.getElementById("EditUIWindow").src = "../EditWidows/WebForm1.aspx?entity=V_UserEmp&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath&ForeignKey=DeptID";
                //YAHOO.example.container.dialog1.show();
                //document.getElementById("yui-gen17-button").style.display = "block";
                document.getElementById("EditUIWindow").src = "../Crm/Customer/ShareCustomer.aspx?r=" + Math.random() + "&type=0&n=" + encodeURI(CustomerName) + "&m=" + encodeURI(Decisionmaker) + "&code=" + Code + "&entity=CrmCustomerInfo&id=" + vid;
                YAHOO.example.container.dialog1.show();
                document.getElementById("yui-gen17-button").style.display = "block";
            }
        } else {   //批量分配
            document.getElementById("EditUIWindow").src = "../Crm/Customer/ShareCustomer.aspx?r=" + Math.random() + "&type=0&n=1&m=1&code=1&entity=CrmCustomerInfo&id=";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen17-button").style.display = "block";
        }
    } else {
        alert("您没有选中任何项");
    }
}
//客户共享
var fnCustomerShare = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    var CustomerName = record.getData("CustomerName");
    var Decisionmaker = record.getData("Decisionmaker");
    var Code = record.getData("Code");
    if (vid != "") {
        document.getElementById("EditUIWindow").src = "../Crm/Customer/ShareCustomer.aspx?r=" + Math.random() + "&type=1&n=" + encodeURI(CustomerName) + "&m=" + encodeURI(Decisionmaker) + "&code=" + Code + "&entity=CrmCustomerShare&id=" + vid;
        YAHOO.example.container.dialog1.show();
        document.getElementById("yui-gen17-button").style.display = "block";
    }
}
//停用客户
var fnCustomerStop = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    if (vid != "") {
        if (confirm("您确定将该客户停用吗?")) {
            var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=CrmCustomerInfo&type=0&json=&id=" + vid;
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            alert("停用客户成功!");
                            RefreshData();
                        }
                        else {
                            alert(str + "\n" + "操作失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    }
}
//自定义方法获取数据
var GetSelectValue = function () {

}

//录入客户
var fnAddOldCustomer = function () {
    window.parent.parent.$("#tabs").tabs('close', '新增客户信息');
    var pagetitle = "新增客户信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=3&flag=3&entity=' + const_EditEntity + '&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//修改客户
var fnModifyCustomer = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    window.parent.parent.$("#tabs").tabs('close', '修改客户信息');
    vname = record.getData("CustomerName");
    var pagetitle = "修改客户信息";
    parent.parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=3&flag=4&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
    parent.parent.NeedRefreshPage = this;
}
//客户浏览
var fnCustomerList = function () {
    //document.getElementById("EditUIWindow").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=AddTime";
    //YAHOO.example.container.dialog1.show();
    //document.getElementById("yui-gen7-button").style.display = "none";
    window.parent.parent.$("#tabs").tabs('close', '客户浏览');
    var pagetitle = "客户浏览";
    parent.parent.addTabs(pagetitle, '../../EditWidows/SubjectList.aspx?entity=V_CrmCustomerInfoSale&order=AddTime');
    parent.parent.NeedRefreshPage = this;
}
//格式化是否历史数据
var formatIsHistory = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}


if (typeof ($) == "undefined") { //屏蔽右键
    parent.parent.unContextMenu(document);
}